package com.lqq.chapter04.ArrayListDemo;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author lqq677
 * @Date 2021/8/10 15:47
 * @Description 解决ArrayList线程不安全方案三：CopyOnWriteArrayList(写时复制)
 */
public class CopyOnWriteArrayListTest {
    public static void main(String[] args) {
        List<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 30; i++) {
            new Thread(() ->{
                list.add(UUID.randomUUID().toString().substring(0,8));
                System.out.println(list);
                    }, String.valueOf(i)).start();
        }
    }
}
